package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

    /*
     * 插入一条订单数据
     * */
    void insertOrders(Orders orders);

    /**
     * 根据订单号查询订单
     *
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     *
     * @param orders
     */
    void update(Orders orders);

    /*
     * 根据参数修改订单信息
     * */
    @Update("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus} ,checkout_time = #{check_out_time} where id = #{id}")
    void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime check_out_time, Long id);

    /*
     * 分页查询历史订单信息
     * */
    Page<Orders> selectOrders(OrdersPageQueryDTO ordersPageQueryDTO);

    /*
    * 根据订单id查询订单信息
    * */
    @Select("select * from orders where id = #{id}")
    Orders selectOrderById(Long id);

    /*
    * 自动查询超时订单
    * */
    @Select("select * from orders where status = #{status} and order_time < #{ordertTime}")
    List<Orders> selectOverTimeOrders(Integer status, LocalDateTime ordertTime);

    /*
    * 根据日期统计店铺营业额
    * */
    BigDecimal selectTurnoverByDate(LocalDateTime beginTime, LocalDateTime endTime, Integer status);

    /*
    * 根据日期统计店铺订单
    * */
    Long selectOrdersByDate(Map map);
}
